import requestManager from "../utils/request.util";
import type {
  PatientRes,
  UserAppointmentRes,
  UserRes,
} from "../../types/user.type";

// 退出登陆
export const logout = () => {
  return requestManager.request<UserRes>({
    url: "/login/logout",
    method: "POST",
  });
};

// 查询用户信息
export const getCmUserById = () => {
  return requestManager.request<UserRes>({
    url: "/cmUser/getCmUserById",
    method: "GET",
  });
};

// 修改用户信息

export const updateCmUser = (params: {
  nickName: string; //用户昵称
  avatarUrl: string; //用户头像
}) => {
  return requestManager.request<UserRes>({
    url: "/cmUser/updateCmUser",
    method: "POST",
    data: params,
  });
};

// 查询我的就诊人列表
export const getPatientList = (isDefault?: number) => {
  return requestManager.request<PatientRes[]>({
    url: "/cmUserPatient/getPatientList",
    method: "GET",
    data: isDefault !== undefined ? { isDefault } : {},
  });
};

// 查询我的预约列表
export const getAppointmentList = (params: {
  regStatus?: number;
  pageNo?: number;
  pageSize?: number;
}) => {
  return requestManager.request<UserAppointmentRes[]>({
    url: "/appointment/getAppointmentList",
    method: "GET",
    data: params,
  });
};

// 添加就诊人
export const addPatient = (params: {
  patientName: string; //患者名
  patientGender: string; //患者性别;1男生2女生3未知genderEnum
  idCard: string; //身份证号
  solarBirthday: string; //阳历生日;阳历生日
  lunarBirthday: string; //阴历生日;阴历生日
}) => {
  return requestManager.request<PatientRes>({
    url: "/cmUserPatient/addPatient",
    method: "POST",
    data: params,
  });
};

// 修改就诊人
export const updatePatient = (params: {
  cmPatientId: number; //就诊人ID
  patientName: string; //患者名
  patientGender: string; //患者性别;1男生2女生3未知genderEnum
  idCard: string; //身份证号
  solarBirthday: string; //阳历生日;阳历生日
  lunarBirthday: string; //阴历生日;阴历生日
}) => {
  return requestManager.request<PatientRes>({
    url: "/cmUserPatient/updatePatient",
    method: "POST",
    data: params,
  });
};

// 删除就诊人
export const deletePatient = (params: {
  cmPatientId: number; //就诊人ID
}) => {
  return requestManager.request<PatientRes>({
    url: "/cmUserPatient/deletePatient",
    method: "POST",
    data: params,
  });
};

// 设置默认就诊人
export const setDefaultPatient = (params: {
  cmPatientId: number; //就诊人ID
}) => {
  return requestManager.request<PatientRes>({
    url: "/cmUserPatient/setDefaultPatient",
    method: "POST",
    data: params,
  });
};
